package mutilthread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025—03—21
 * Time: 10:27
 */
public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        //获取当前线程的实例（main）
        Thread mainThread = Thread.currentThread();//获取线程的引用
        Thread t = new Thread(() -> {
            //需要在 t 中调用主线程.join
            //让t线程等待主线程
            System.out.println("t 线程开始等待");
            try {
                mainThread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t 线程等待结束");
        });
        t.start();
        Thread.sleep(2000);
        System.out.println("main 线程结束");
    }
}
